<?php
	defined('_JEXEC') or die('Restricted access');
	$local_hide_title = false;
	$a_query_parameter = $arguments[0];
	$a_current_field = $arguments[1];
	$a_current_field_no = $arguments[2];
	$a_fields_count = $arguments[3];
	$a_current_row_no = $arguments[4];
	$a_rows_count  = $arguments[5];
	$a_sender = $arguments[6];
	$local_field_name = $this->get_db_field_name($a_current_field);
	//echo "local_field_name: $local_field_name<br>";
    
			if ((($a_current_row_no == 0) || ($a_current_row_no == -1)) && ($a_current_field_no == 0))
			{
				// edit_panel_content
				$this->add_style_sheet_property(".".$this->get_tag_name(t_field_grid::style_edit_panel_content,array($this->name)),"margin-left","auto");
				$this->add_style_sheet_property(".".$this->get_tag_name(t_field_grid::style_edit_panel_content,array($this->name)),"margin-right","auto");

				// h5
				$this->add_style_sheet_property("#".$this->name." h5","background-color","lightskyblue");
				$this->add_style_sheet_property("#".$this->name." h5","margin-top","2px");
				$this->add_style_sheet_property("#".$this->name." h5","margin-bottom","0px");
				$this->add_style_sheet_property("#".$this->name." h5","display","inline-block");
				$this->add_style_sheet_property("#".$this->name." h5","min-height","30px");
				$this->add_style_sheet_property("#".$this->name." h5","padding-right","3px");
				$this->add_style_sheet_property("#".$this->name." h5","padding-top","2px");
				$this->add_style_sheet_property("#".$this->name." h5","position","relative");
				$this->add_style_sheet_property("#".$this->name." h5","text-align","right");
				$this->add_style_sheet_property("#".$this->name." h5","vertical-align","top");
				$this->add_style_sheet_property("#".$this->name." h5","width","215px");
				//label
				$this->add_style_sheet_property("#".$this->name." label","display","inline");
				$this->add_style_sheet_property("#".$this->name." label","margin-left","7px");
				$this->add_style_sheet_property("#".$this->name." label","position","relative");
				$this->add_style_sheet_property("#".$this->name." label","vertical-align","top");

				// ul
				$this->add_style_sheet_property("#".$this->name." ul","padding","0px");
				
				// li
				$this->add_style_sheet_property("#".$this->name." li","padding","10px");
				$this->add_style_sheet_property("#".$this->name."_data_panel_0","width","85%");
				$this->add_style_sheet_property("#".$this->name."_edit_panel_0","width","60px");
				

				// textarea, input
				$this->add_style_sheet_property("#".$this->name." textarea, input","width","553px");
				$this->add_style_sheet_property("#".$this->name." textarea, input","margin-left","7px");
				$this->add_style_sheet_property("#".$this->name." textarea, input","position","relative");
				$this->add_style_sheet_property("#".$this->name." textarea, input","vertical-align","top");
				
				//
				$this->add_style_sheet_property("#".$this->main_tag->name."_nav input","width","10px");
				$this->add_style_sheet_property("#".$this->main_tag->name."_nav input","margin-left","0px");
			}	

	
			global $g_strings_utility_namespace;
			//echo "a_current_field->type: $a_current_field->type<br>";
			$l_value = $a_query_parameter->sql_values[$a_current_field_no];
			$local_special_column = $this->special_columns_array[$a_current_field_no];
			if ((isset($local_special_column)) && ($local_special_column[t_field_grid::special_column_parameters_column_field_type] == t_field_grid::special_column_type_column_url_parameter_value))
			{
				$l_value = $this->get_special_column_type_column_url_parameter_value($a_current_field_no);
				//echo "l_value: $l_value<br>";
			}
			if (t_query_parameter::get_field_type($a_current_field->type) == 'datetime')
				$l_value = $g_strings_utility_namespace->get_ambient_datetime_fromat_from_mysql_datetime_value($a_query_parameter->sql_values[$a_current_field_no]);
			else if (t_query_parameter::get_field_type($a_current_field->type) == 'date')
				$l_value = $g_strings_utility_namespace->get_ambient_datetime_fromat_from_mysql_date_value($a_query_parameter->sql_values[$a_current_field_no]);
			else if (t_query_parameter::get_field_type($a_current_field->type) == 'time')
				$l_value = $g_strings_utility_namespace->get_ambient_datetime_fromat_from_mysql_time_value($a_query_parameter->sql_values[$a_current_field_no]);				
			//echo "a_query_parameter->sql_values[$a_current_field_no]: ". $a_query_parameter->sql_values[$a_current_field_no] ." - l_value: $l_value<br>";
//			$local_is_main_table = ($a_query_parameter->main_table_name == t_query_parameter::prepare_table_name($a_current_field->table));
			$local_result = '';
			$local_new_row = '';
			$local_special_column = $this->special_columns_array[$a_current_field_no];
			if ((($a_current_row_no == 0) || ($a_current_row_no == -1)) && ($a_current_field_no == 0))
			{
				//$local_result = "<tbody>";
			}
			if ($a_current_row_no >= 0)
			{
				//echo "a_current_row_no:$a_current_row_no<br>";
				$local_row_name = $this->get_tag_name(t_field_grid::tag_prefix_row,array($a_current_row_no));
				if ($a_current_field_no == 0) 
				{
					// open row
					$local_result .= "<ul id=\"". $local_row_name ."\" style=\"list-style: none outside none; width: 100%; float: left;\">";

					if (($a_current_field->primary_key == 1) && 
						(($this->is_event_able(t_base_field::field_event_type_on_selected)) ||
						($this->is_event_able(t_base_field::field_event_type_on_edit)) ||
						($this->is_event_able(t_base_field::field_event_type_on_cancel)) ||
						($this->is_event_able(t_base_field::field_event_type_on_save)) ||
						($this->is_event_able(t_base_field::field_event_type_on_insert)) ||
						($this->is_event_able(t_base_field::field_event_type_on_delete))))
					{
						//EDIT PANEL
						$local_result .= "<li id=\"".$this->name."_edit_panel_". $a_current_row_no ."\" style=\"float: left;\"><div id=\"edit_panel_content_". $a_current_row_no ."\" class=\"".$this->get_tag_name(t_field_grid::style_edit_panel_content,array($this->name))."\">";
						// status image
						$local_result .= "<div><a><image id=\"". $this->get_tag_name(t_field_grid::tag_prefix_row_message,array($a_current_row_no)) ."\" class=\"".$this->get_tag_name(t_field_grid::style_name_none,array($this->name))."\"></image></a></div>";
					}
				}
				//echo "a_current_field->table:". $a_current_field->table."<br>";
				//echo "a_current_field->primary_key:". $a_current_field->primary_key."<br>";
                if (($a_current_field->primary_key == 1) /*&& ($local_is_main_table)*/)
				{
					
					if (($this->is_event_able(t_base_field::field_event_type_on_selected)) || ($this->is_multi_action_form_active()))
					{
						$local_result .= "<div align=\"center\"><input type=\"checkbox\" value=\"enabled\" ".$this->get_field_event_script(t_base_field::field_event_type_on_selected,"event,'".$a_query_parameter->sql_values[$a_current_field_no]."'")."/></div>";
					}	
					if ($this->is_event_able(t_base_field::field_event_type_on_edit))
					{
						$local_result .= "<div align=\"center\"><a id=\"". $this->get_tag_name(t_field_grid::tag_prefix_row_edit,array($a_current_row_no)) ."\" href=\"#$local_row_name\" ><span ".$this->get_field_event_script(t_base_field::field_event_type_on_edit,"event,'$a_current_row_no'").">".$this->lang[t_field_grid::language_position_modify]."</span></a></div>";
					}
					if ($this->is_event_able(t_base_field::field_event_type_on_cancel))
					{					
						$local_result .= "<div align=\"center\"><a style=\"display: none\" id=\"". $this->get_tag_name(t_field_grid::tag_prefix_row_cancel,array($a_current_row_no)) ."\" href=\"#$local_row_name\" ><span ".$this->get_field_event_script(t_base_field::field_event_type_on_cancel,"event,'$a_current_row_no',true").">".$this->lang[t_field_grid::language_position_cancel]."</span></a></div>";
					}
					if ($this->is_event_able(t_base_field::field_event_type_on_save))
					{
						$local_result .= "<div align=\"center\"><a style=\"display: none\" id=\"". $this->get_tag_name(t_field_grid::tag_prefix_row_save,array($a_current_row_no)) ."\" href=\"#$local_row_name\" ><span ".$this->get_field_event_script(t_base_field::field_event_type_on_save,"event,'$a_current_row_no'").">".$this->lang[t_field_grid::language_position_save]."</span></a></div>";
					}
					if ($this->is_event_able(t_base_field::field_event_type_on_insert))
					{
						$local_result .= "<div align=\"center\"><a id=\"". $this->get_tag_name(t_field_grid::tag_prefix_row_insert,array($a_current_row_no)) ."\" href=\"#".$this->get_tag_name(t_field_grid::tag_prefix_row,array('ins'))."\" ><span ".$this->get_field_event_script(t_base_field::field_event_type_on_insert,"event,'ins'").">".$this->lang[t_field_grid::language_position_insert]."</span></a></div>";
					}	
					if ($this->is_event_able(t_base_field::field_event_type_on_delete))
					{
						$local_result .= "<div align=\"center\"><a id=\"". $this->get_tag_name(t_field_grid::tag_prefix_row_delete,array($a_current_row_no)) ."\" href=\"#$local_row_name\" ><span ".$this->get_field_event_script(t_base_field::field_event_type_on_delete,"event,'$a_current_row_no'").">".$this->lang[t_field_grid::language_position_delete]."</span></a></div>";
					}	
					// CLOSE EDIT PANEL
					$local_result .= "</li>";
				}
				if ($a_current_field_no == 0) 
				{
					// OPEN DATA_PANEL
					$local_result .= "<li class=\"".$this->name."_row_class\" id=\"".$this->name."_data_panel_". $a_current_row_no ."\" style=\"float: left;\">";
				}	
                
				//
				$local_field = $this->parent_part->get_field($this->get_special_column_field('all',$local_field_name));
				// no edit mode
				if ((isset($local_field)) && (method_exists($local_field,'get_included_in_html_structure_no_edit_mode')))
				{
					$local_special_column = $this->special_columns_array[$a_current_field_no];
					$local_code = $local_field->get_included_in_html_structure_no_edit_mode($this->get_tag_name(t_field_grid::tag_prefix_value,array($a_current_row_no,$this->get_col_value($a_current_field_no))),
						$l_value,$a_query_parameter->sql_values[$local_special_column[t_field_grid::special_column_parameters_column_id_number]]);
					//echo $local_special_column[t_field_grid::special_column_parameters_column_id_number] ." - ".$a_query_parameter->sql_values[$local_special_column[t_field_grid::special_column_parameters_column_id_number]]."<br>";	
				}
				else
					$local_code = "<label id=\"". 
						$this->get_tag_name(t_field_grid::tag_prefix_value,array($a_current_row_no,$this->get_col_value($a_current_field_no))) .
						"\">".$l_value."</label>";
				//	
				$local_special_column = $this->special_columns_array[$a_current_field_no];
				if ((isset($local_special_column)) && 
					(($local_special_column[t_field_grid::special_column_parameters_column_field_type] == t_field_grid::special_column_type_hidden_column)||
					(($local_special_column[t_field_grid::special_column_parameters_column_field_type] == t_field_grid::special_column_type_column_url_parameter_value) && (strtoupper($this->get_special_column_type_parameter_value($a_current_field_no,2)) !== 'TRUE'))))
				{
					$local_style = 'style="display: none"';
				}    
				else
					$local_style = '';
				// title and content column
				$local_hide_title = (($local_hide_title) ||	
					($local_special_column[t_field_grid::special_column_parameters_column_field_type] == t_field_grid::special_column_type_column_title_hide));
				if (!$local_hide_title)
					$local_title = "<h5 id=\"" . 
					$this->get_tag_name('_c_%s_',array($a_current_field_no)) .
					"\">".$a_current_field->name."</h5>";
				else
					$local_title = "";
				// open column
				$local_result .= "<div $local_style id=\"" . 
					$this->get_tag_name(t_field_grid::tag_prefix_column,array($a_current_row_no,$a_current_field_no)) .
					"\" >$local_title$local_code";		
				if ($this->is_event_able(t_base_field::field_event_type_on_edit))
				{
					// EDIT MODE
					if (isset($local_field))
					{

						//echo "IT IS SPECIAL COLUMN<br>";
						//if ($this->is_description_field_required($local_special_column[t_field_grid::special_column_parameters_column_field_type]))
						$local_key_col_num = $local_special_column[t_field_grid::special_column_parameters_column_id_number];
						//else
						$local_col_num = $local_special_column[t_field_grid::special_column_parameters_column_description_number];
						$local_result .= $local_field->get_included_in_html_structure(
							$this->get_special_column_field($a_current_row_no,$local_field_name),
							false,	$this->get_tag_name(t_field_grid::tag_prefix_value_edit,array($a_current_row_no,$this->get_col_value($local_key_col_num))),
							$a_current_row_no);
								
					}
					else
					{		
						$local_disabled = '';
						if (isset($local_special_column))
							$local_disabled = ' disabled="disabled" ';
						
						$local_result .="<textarea style=\"display: none\" $local_disabled id=\"". 
							$this->get_tag_name(t_field_grid::tag_prefix_value_edit,array($a_current_row_no,$this->get_col_value($a_current_field_no))) .
							"\"></textarea>";
					}
				}	
				// CLOSE COLUMN
				$local_result .="</div>";
				if ($a_current_field_no == ($a_fields_count-1))
				{
					// CLOSE DATA COLUMN
					$local_result .= "</li>";
					// close row
					$local_result .= "</ul>";
				}
			}	
			if (($a_current_row_no == ($a_rows_count-1)) && ($a_current_field_no == ($a_fields_count-1)))
			{
				
				if ($this->is_event_able(t_base_field::field_event_type_on_insert))
				{	
					// open row
					$local_new_row .= "<ul id=\"". $this->get_tag_name(t_field_grid::tag_prefix_row,array('ins')) ."\" style=\"list-style: none outside none; width: 100%; float: left;\">";
					//EDIT PANEL
					$local_new_row .= "<li id=\"edit_panel_ins\" style=\"float: left;\"><div id=\"edit_panel_content_ins\" class=\"".$this->get_tag_name(t_field_grid::style_edit_panel_content,array($this->name))."\">";
					$local_new_row .= "<div><a><image id=\"". $this->get_tag_name(t_field_grid::tag_prefix_row_message,array('ins')) ."\" class=\"".$this->get_tag_name(t_field_grid::style_name_none,array($this->name))."\"></image></a></div>";
                        
                    //echo "local_new_row - $local_new_row<br>";	
					if (($this->is_event_able(t_base_field::field_event_type_on_selected)) || ($this->is_multi_action_form_active()))
                    {
                        
                        $local_new_row .= "<div align=\"center\"></div>";
                    }	
                    if ($this->is_event_able(t_base_field::field_event_type_on_edit))
                    {
                        $local_new_row .= "<div align=\"center\"></div>";
                    }
                    if ($this->is_event_able(t_base_field::field_event_type_on_cancel))
                    {					
                        $local_new_row .= "<div align=\"center\"><a style=\"display: none\" id=\"". $this->get_tag_name(t_field_grid::tag_prefix_row_cancel,array('ins')) ."\" href=\"#". $this->get_tag_name(t_field_grid::tag_prefix_row_insert,array('ins'))."\" ><span ".$this->get_field_event_script(t_base_field::field_event_type_on_cancel,"event,'ins',true").">Cancel</span></a></div>";
                    }
                    if ($this->is_event_able(t_base_field::field_event_type_on_save))
                    {
                        $local_new_row .= "<div align=\"center\"><a style=\"display: none\" id=\"". $this->get_tag_name(t_field_grid::tag_prefix_row_save,array('ins')) ."\" href=\"#". $this->get_tag_name(t_field_grid::tag_prefix_row_insert,array('ins'))."\" ><span ".$this->get_field_event_script(t_base_field::field_event_type_on_save,"event,'ins'").">Save</span></a></div>";
                    }
                    if ($this->is_event_able(t_base_field::field_event_type_on_insert))
                    {
                        $local_new_row .= "<div align=\"center\"></div>";
                    }
                    if ($this->is_event_able(t_base_field::field_event_type_on_delete))
                    {
                        $local_new_row .= "<div align=\"center\"></div>";;
                    }	
					// CLOSE EDIT PANEL
					$local_new_row .= "</div></li>";
					// OPEN DATA_PANEL
					$local_new_row .= "<li id=\"data_panel_ins\" style=\"float: left;\">";
				
					for ($i=0; $i <$a_fields_count; $i++)
                    {
						$local_db_field = mysqli_fetch_field_direct($a_query_parameter->sql_result_query, $i);
						//echo "local_db_field->orgname: $local_db_field->orgname<br>";
						$local_new_row .= "<div id=\"". 
							$this->get_tag_name(t_field_grid::tag_prefix_column,array('ins',$i)) .
							"\"><label id=\"". 
							$this->get_tag_name(t_field_grid::tag_prefix_value,array('ins',$this->get_col_value($i))) .
							"\"></label>";
						
						//echo "a_current_field_no: $a_current_field_no<br>";
						//echo "this->get_special_column_field('all',$a_current_field->orgname): " .$this->get_special_column_field('all',$a_current_field->orgname)."<br>";
						$local_special_column = $this->special_columns_array[$i]; 
						if (isset($local_special_column) && ($local_special_column[t_field_grid::special_column_parameters_column_description_number] == $i))
						{
							//echo "local_special_column[t_field_grid::special_column_parameters_column_description]: ".$local_special_column[t_field_grid::special_column_parameters_column_description]."<br>";
							$local_field = $this->parent_part->get_field($this->get_special_column_field('all',$local_special_column[t_field_grid::special_column_parameters_column_description]));
						}	
						else
							$local_field = null;
							
						if (isset($local_field))
						{
	   
							//echo "IT IS SPECIAL COLUMN i:$i<br>";
							//if ($this->is_description_field_required($local_special_column[t_field_grid::special_column_parameters_column_field_type]))
							$local_key_col_num = $local_special_column[t_field_grid::special_column_parameters_column_id_number];
							//else
							$local_col_num = $local_special_column[t_field_grid::special_column_parameters_column_description_number];
							$local_name = $this->get_tag_name(t_field_grid::tag_prefix_value_edit,array('ins',$this->get_col_value($local_col_num)));
							//echo "$local_name: $local_name<br>"; 
							//print_r($local_field);
							$local_tags = $local_field->get_included_in_html_structure(
								$this->get_special_column_field('ins',$local_special_column[t_field_grid::special_column_parameters_column_description]),
								false,	$this->get_tag_name(t_field_grid::tag_prefix_value_edit,array('ins',$this->get_col_value($local_key_col_num))),
								'ins');
							//echo "local_tags: $local_tags<br>";
							$local_new_row .= "<h5 style=\"display: none\" id=\"". $local_name ."_header\">".$local_db_field->name."</h5>".$local_tags;
						}
						else
						{
							$l_value = '';
							if ((isset($local_special_column)) && ($local_special_column[t_field_grid::special_column_parameters_column_field_type] == t_field_grid::special_column_type_column_url_parameter_value))
							{
								$l_value = $this->get_special_column_type_column_url_parameter_value($i);
								//echo "l_value: $l_value<br>";
							}
							
							$local_disabled = '';
							if (isset($local_special_column))
								$local_disabled = ' disabled="disabled" '; // self::special_column_type_hidden_column, self::special_column_type_no_edit_column
							$local_name = $this->get_tag_name(t_field_grid::tag_prefix_value_edit,array('ins',$this->get_col_value($i)));
							$local_new_row .= "<h5 style=\"display: none\" id=\"". $local_name ."_header\">".$local_db_field->name."</h5><textarea $local_disabled id=\"". 
							    $local_name ."\" style=\"display: none\">$l_value</textarea>";
						}   
						$local_new_row .= "</div>";                        
						
                    }    
					// CLOSE DATA COLUMN
					$local_new_row .= "</div></li>";
					// close row
					$local_new_row .= "</ul>";						
					//$local_result .= "$local_new_row</tbody>";
					$local_result .= "$local_new_row";
				}
				
					
			}		
			$local_return = $local_result;
		//print_r($local_return)
		
		
	
		
?>    